define([
	'xss',
	'layer',
	'../../Shop/module/STH_main.js',
], function (xss, layer, main) {

    return {


        //加入模块
        noticeAddM: function (con) {
            var _this = this,
	    	    key = con.key,
	    	    prop = con.prop,
	    	    order = con.order,
	    	    newPanel = main.getPanel("notice"),
	            newEdit = main.getEdit("notice");

            /*展示*/
            $(newPanel).attr("order", order);
            $(newPanel).attr("key", key);
            $(newEdit).attr("key", key);
            $(newEdit).css("display", "none");
            $(newPanel).find('.notice-box').html(prop.noticeValue);
            $(newEdit).find("textarea[name='notice']").val(prop.noticeValue);

            //延时顺序重定位
            var edLength = $(".hb_box .panel-comp").length;
            if ($(".hb_box .panel-comp").length < 1 || order > parseInt($(".hb_box .panel-comp").eq(edLength - 1).attr("order"))) {
                $(".hb_box").append(newPanel);
            } else if (order < parseInt($(".hb_box .panel-comp").eq(0).attr("order"))) {
                $(".hb_box").prepend(newPanel);
            } else {
                for (var r = 0; r < edLength; r++) {
                    if (order > parseInt($(".hb_box .panel-comp").eq(r).attr("order")) && order < parseInt($(".hb_box .panel-comp").eq(r + 1).attr("order"))) {
                        $(".hb_box .panel-comp").eq(r).after(newPanel);
                        break;
                    }
                }
            }
            $(".edit-panel").append(newEdit);
            _this.noticeActive(newPanel, newEdit, key);
        },

        //常规操作
        noticeActive: function (thisPanel, thisEdit, key) {
            var _this = this;
            if (typeof (g_data[key].prop.noticeValue) == "undefined") {
                g_data[key].prop = {
                    "noticeValue": ""
                }
            }

            //属性操作
            function propChange(thisPanel, thisEdit, key) {
                $(thisEdit).find("textarea[name='notice']").unbind('blur').blur(function () {
                    var _this = this;
                    notice_box = $(thisPanel).find(".notice-box"),
                    noticeVal = filterXSS(main.html_encode($(this).val()));
                    if (noticeVal != null && noticeVal != "") {
                        notice_box.html(noticeVal); 
                        g_data[key].prop.noticeValue = noticeVal;
                    } else {
                        notice_box.html('我就是公告啊!');
                        g_data[key].prop.noticeValue = "";
                    }
                });

            }
            propChange(thisPanel, thisEdit, key); 
            main.saveClick();
            main.moduleActive();
            main.dragEdit();
        }

    }
});